----------------------------------Effect Variables--------------------------------------
EFFECT.effectID = 4 -- Whatever value you want as long as it doesn't override any other effects' IDs.
EFFECT.effectName = "DoT/HoT effect"
EFFECT.effectDuration = 0
EFFECT.effectCurrentStacks = 0
EFFECT.effectOldStacks = 0
EFFECT.effectMaxStacks = 1
EFFECT.effectFinished = false
---------------------------------------------------------------------------------------

function EFFECT:Init(pl, effname, atk, add, dur, maxstacks)
	if(pl.Effects != nil)then
		for k, v in pairs(pl.Effects)do
			print(""..v.effectName..":"..effname.."")
			if(v.effectName == effname and !v.RemoveMe)then
				v:AddStack()
				return v
			end
		end
	end
	local a = table.Copy(self)
	a.effectName = effname
	a.effectDuration = dur
	a.effectValueAdded = 0
	a.effectMaxStacks = maxstacks
	a.effectCurrentStacks = 1
	a.effectOldStacks = 0
	a.DestroyTime = CurTime() + dur
	a.CurMult = mult
	a.CurAdd = add
	a.RemoveMe = false
	a.DamageType = atk
	a.TickDamage = add
	a.NextTick = CurTime() + 1
	a.Think = self.Think
	a.AddStack = self.AddStack
	a.DealDamage = self.DealDamage
	if(pl.Effects == nil)then
		pl.Effects = {a}
	else
		table.insert( pl.Effects, a)
	end
	return a
end

function EFFECT:AddStack()
	self.DestroyTime = CurTime() + self.effectDuration
	if(self.effectCurrentStacks < self.effectMaxStacks)then
		print("adding one stack to "..self.effectOldStacks.."-"..self.effectCurrentStacks.."-"..self.effectMaxStacks.."")
		self.effectCurrentStacks = self.effectCurrentStacks + 1
	end
end

function EFFECT:Think(pl)
	if(!pl:Alive())then
		self.RemoveMe = true
	end
	if(!self.RemoveMe && pl:Alive())then
		if(CurTime() >= self.DestroyTime)then
			self.effectOldStacks = 0
			self.effectCurrentStacks = 0
			self.RemoveMe = true
		end
		if(CurTime() > self.NextTick)then
			self:DealDamage(self.TickDamage*self.effectCurrentStacks, self.DamageType[1], pl, self.DamageType[2])
			self.NextTick = CurTime() + 1
		end
	end
end

function EFFECT:DealDamage(dmg, attacker, target, dmgtype)
	if(SERVER)then
		local dmginfo = DamageInfo()
		
		dmginfo:SetDamage( dmg )
		dmginfo:SetDamageType( dmgtype )
		dmginfo:SetAttacker( attacker )
		dmginfo:SetDamageForce( Vector( 0, 0, 1000 ) )
		
		target:TakeDamageInfo( dmginfo )
	end
end

function EFFECT:Remove()
	self.RemoveMe = true
end

function EFFECT:Reset(pl)

end




